package com.headfirst.dmp.utils

import org.apache.spark.sql.Row

import scala.collection.mutable.ListBuffer

/**
  * Tag工具类
  */
object TagUtils {

  val getAllUserId =
    """
      |imei != "" or imeimd5!="" or imeisha1 !="" or
      |idfa != "" or idfamd5!="" or idfasha1 !="" or
      |mac != "" or macmd5!="" or macsha1 !="" or
      |androidid != "" or androididmd5!="" or androididsha1 !="" or
      |openudid != "" or openudidmd5!="" or openudidsha1 !=""
    """.stripMargin



  def getAllUserId(row:Row):ListBuffer[String] = {

    val userIds = new collection.mutable.ListBuffer[String]()


    if(row.getAs[String]("imei").nonEmpty) userIds.append("IM:"+row.getAs[String]("imei").toUpperCase)
    if(row.getAs[String]("idfa").nonEmpty) userIds.append("DF:"+row.getAs[String]("idfa").toUpperCase)
    if(row.getAs[String]("mac").nonEmpty) userIds.append("MC"+row.getAs[String]("mac").toUpperCase)
    if(row.getAs[String]("androidid").nonEmpty) userIds.append("AD:"+row.getAs[String]("androidid").toUpperCase)
    if(row.getAs[String]("openudid").nonEmpty) userIds.append("OD:"+row.getAs[String]("openudid").toUpperCase)

    if(row.getAs[String]("imeimd5").nonEmpty) userIds.append("IM5:"+row.getAs[String]("imeimd5").toUpperCase)
    if(row.getAs[String]("idfamd5").nonEmpty) userIds.append("DF5:"+row.getAs[String]("idfamd5").toUpperCase)
    if(row.getAs[String]("macmd5").nonEmpty) userIds.append("MC5"+row.getAs[String]("macmd5").toUpperCase)
    if(row.getAs[String]("androididmd5").nonEmpty) userIds.append("AD5:"+row.getAs[String]("androididmd5").toUpperCase)
    if(row.getAs[String]("openudidmd5").nonEmpty) userIds.append("OD5:"+row.getAs[String]("openudidmd5").toUpperCase)

    if(row.getAs[String]("imeisha1").nonEmpty) userIds.append("IM1:"+row.getAs[String]("imeisha1").toUpperCase)
    if(row.getAs[String]("idfasha1").nonEmpty) userIds.append("DF1:"+row.getAs[String]("idfasha1").toUpperCase)
    if(row.getAs[String]("macsha1").nonEmpty) userIds.append("MC1"+row.getAs[String]("macsha1").toUpperCase)
    if(row.getAs[String]("androididsha1").nonEmpty) userIds.append("AD1:"+row.getAs[String]("androididsha1").toUpperCase)
    if(row.getAs[String]("openudidsha1").nonEmpty) userIds.append("OD1:"+row.getAs[String]("openudidsha1").toUpperCase)


    //返回值
    userIds

  }

}
